import type {
  IPaymentInfoRes,
  IMemberItem,
  IUpdateMemberLeadingInfoData,
  IAttacheInfo,
  MemberData,
  PerfectUserInfoData,
  UnitListResult,
  UnitAddData,
  SetDefaultIdentityData,
  UserStatistics
} from './types';
import type { IResData, IQuery } from '@/api/indexTypes';
import { defHttp } from '@/utils/http';
import { exc, root } from '@/api/apiRoot';
import type { IUserInfo } from '../login/types';

export const Api = {
  // contact: exc + 'information/list/3/5',
  contactUsApi: exc + 'configApp/contactUs',
  paymentInfo: root + 'member/getPaymentInfo',
  pageLeadingList: root + 'LeadingMember/pageLeadingList',
  updateMemberLeadingInfo: root + 'LeadingMember/updateMemberLeadingInfo',
  delResponsiblePerson: root + 'LeadingMember/leading/delete',
  getAttacheInfo: root + 'member/getAttacheInfo',
  getMemberCount: root + 'member/getMemberCount',
  // 缴费信息 缴费函导出
  paymentExport: root + 'member/paymentExport',
  getInformation: root + 'app-user-info/getUserInfo',
  upInformation: root + 'app-user-info/update',
  perfectUserInfo: root + 'app-user-info/perfectUserInfo',
  unitList: root + 'companies/user/list',
  unitAdd: root + 'companies/add',
  unitDel: root + 'companies/del',
  unitEdit: root + 'companies/edit',
  setDefaultIdentity: root + 'app-user-info/setDefaultIdentity',
  /**用户身份待办数据统计 */
  getUserStatistics: root + 'user/statistics/getUserStatistics'
};

/**
 * 获取关于我们
 * @returns
 */
export function getContactUs() {
  return defHttp.get<string>({
    url: Api.contactUsApi,
  });
}

/**
 * 查看我的会员缴费
 * @export
 * @param {number} id
 * @return {*}  {Promise<IPaymentInfoRes>}
 */
export function paymentInfo(id: number): Promise<IPaymentInfoRes> {
  return defHttp.get({
    url: Api.paymentInfo + `/${id}`,
  });
}

/**
 * 成员管理 - 成员列表(负责人 && 成员)
 * @export
 * @param {IPageLeadingListData} data
 * @return {*}  {Promise<IMemberItem>}
 */
export function pageLeadingList(data: IQuery): Promise<IResData<IMemberItem>> {
  return defHttp.post({
    url: Api.pageLeadingList,
    data,
  });
}

/**
 * 成员管理 - 添加 / 编辑
 * @export
 * @param {IUpdateMemberLeadingInfoData} data
 * @return {*}  {Promise<any>}
 */
export function updateMemberLeadingInfo(data: IUpdateMemberLeadingInfoData): Promise<any> {
  return defHttp.post({
    url: Api.updateMemberLeadingInfo,
    data,
  });
}

/**
 * 删除成员
 * @export
 * @param {number} id
 * @return {*}  {Promise<any>}
 */
export function delResponsiblePerson(id: number): Promise<any> {
  return defHttp.post({
    url: Api.delResponsiblePerson + `/${id}`,
  });
}

/**
 * 获取专员信息
 * @export
 * @param {number} id
 * @return {*}  {Promise<IAttacheInfo>}
 */
export function attacheInfo(id: number): Promise<IAttacheInfo> {
  return defHttp.get({
    url: Api.getAttacheInfo + `/${id}`,
  });
}

/**
 * 超级管理员 - 获取会员单位总数
 * @export
 * @return {*}  {Promise<number>}
 */
export function getMemberCount(): Promise<number> {
  return defHttp.get({
    url: Api.getMemberCount,
  });
}

/**
 * 获取会员资料
 * @export
 */
export function getMemberData() {
  return defHttp.get<IUserInfo>({
    url: Api.getInformation,
  });
}

/**
 * 修改会员资料
 * @export
 * @return {*}  {Promise<any>}
 */
export function upMemberData(data: MemberData): Promise<any> {
  return defHttp.post({
    url: Api.upInformation,
    data
  });
}

/**
 * @description 快捷完善资料
 * @date 04/07/2023
 * @export
 * @param {PerfectUserInfoData} data
 */
export function perfectUserInfo(data: PerfectUserInfoData) {
  return defHttp.post({
    url: Api.perfectUserInfo,
    data
  })
}

/**
 * @description 获取单位列表
 * @date 06/07/2023
 * @export
 */
export function unitList() {
  return defHttp.get<UnitListResult[]>({
    url: Api.unitList
  })
}

/**
 * @description 添加单位
 * @date 06/07/2023
 * @export
 * @param {UnitAddData} data
 */
export function unitAdd(data: UnitAddData) {
  return defHttp.post({
    url: Api.unitAdd,
    data
  })
}

/**
 * @description 编辑单位
 * @date 07/07/2023
 * @export
 * @param {({ id: number } & UnitAddData)} data
 */
export function unitEdit(data: { id: number } & UnitAddData) {
  return defHttp.post({
    url: Api.unitEdit,
    data
  })
}

/**
 * @description 删除单位
 * @date 07/07/2023
 * @export
 * @param {number} id
 */
export function unitDel(id: number) {
  return defHttp.get({
    url: Api.unitDel,
    data: { id }
  })
}

/**
 * @description 设置默认单位
 * @date 07/07/2023
 * @export
 * @param {SetDefaultIdentityData} data
 */
export function setDefaultIdentity(data: SetDefaultIdentityData) {
  return defHttp.post({
    url: Api.setDefaultIdentity,
    data
  })
}
/**
 * 用户身份数据统计
 * @returns 
 */
export function getUserStatistics() {
  return defHttp.get<UserStatistics>({
    url: Api.getUserStatistics,
  })
}